//! 彩色控制台输出示例
//!
//! 运行方式：
//! ```bash
//! cargo run --example colored_console --features color
//! ```

#[cfg(feature = "color")]
use log4r::appender::{Appender, ConsoleAppender};
#[cfg(feature = "color")]
use log4r::{Level, LogEvent};

#[cfg(feature = "color")]
fn main() {
    // 创建彩色控制台 appender
    let appender = ConsoleAppender::new().with_colored();

    println!("=== 彩色日志输出演示 ===\n");

    // 输出各级别日志
    let levels = [
        (Level::Trace, "这是 TRACE 级别日志 - 灰色"),
        (Level::Debug, "这是 DEBUG 级别日志 - 蓝色"),
        (Level::Info, "这是 INFO 级别日志 - 绿色"),
        (Level::Warn, "这是 WARN 级别日志 - 黄色"),
        (Level::Error, "这是 ERROR 级别日志 - 红色"),
        (Level::Fatal, "这是 FATAL 级别日志 - 亮红色粗体"),
    ];

    for (level, message) in levels {
        let event = LogEvent::new(level, "colored_example", message);
        appender.write(&event).ok();
    }

    println!("\n=== 演示结束 ===");
}

#[cfg(not(feature = "color"))]
fn main() {
    eprintln!("请使用 --features color 运行此示例:");
    eprintln!("  cargo run --example colored_console --features color");
}
